﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Microsoft.WindowsCE.Forms;
using ZYOPPC.基本概念;

namespace ZYOPPC
{
    public partial class QMCellCtrl : UserControl
    {
        public QMCellCtrl()
        {
            InitializeComponent();
        }

        private DataRow[] rowCell;
        public DataRow[] row宫
        {
            set
            {
                rowCell = value;

                if (null != rowCell)
                {
                    // Sigle Value vs. Position
                    theDoor = (e八门)Enum.Parse(typeof(e八门), rowCell[0]["八门"].ToString(), false);
                    theGod = rowCell[0]["八神"].ToString();

                    //retrieve 天盘  ************
                    String stars = rowCell[0]["天盘九星"].ToString();
                    String UpperQYs = rowCell[0]["天盘三奇六仪"].ToString();
                    int UpperCount = UpperQYs.Length;
                    // 假设 ["天盘三奇六仪"]与["天盘九星"] 总是一致的

                    theUpperQiYi = new e三奇六仪[UpperCount];
                    theStar = new e九星[UpperCount];

                    for (int t = 0; t < UpperCount; t++)
                    {
                        theStar[t] = (e九星)Enum.Parse(typeof(e九星), stars.Substring(t * 2, 2), false);
                        theUpperQiYi[t] = (e三奇六仪)Enum.Parse(typeof(e三奇六仪), UpperQYs.Substring(t, 1), false);
                    }//for t

                    // retrieve 地盘  ****************
                    int rowsCount = rowCell.GetLength(0);

                    theDownQiYi = new e三奇六仪[rowsCount];
                    thePalace = new e九宫数[rowsCount];
                    isZF = false;
                    for (int i = 0; i < rowsCount; i++)
                    {
                        thePalace[i] = (e九宫数)rowCell[i]["九宫数"];
                        theDownQiYi[i] = (e三奇六仪)Enum.Parse(typeof(e三奇六仪), rowCell[i]["地盘三奇六仪"].ToString(), false);
                        isZF = isZF || (bool)rowCell[i]["is值符"];
                    }//for i

                    // Update UI
                    this.labelGodDoor.Text = this.八神 + " " + this.八门.ToString();
                    this.labelGodDoor.ForeColor = (isZF ? Color.Red : Color.Black);
                    this.labelUpper.Text = String.Empty;
                    for (int t = 0; t < this.天盘奇仪.GetLength(0); t++)
                    {
                        this.labelUpper.Text += this.九星[t].ToString() + this.天盘奇仪[t].ToString();
                    }
                    this.labelDown.Text = String.Empty;
                    for (int i = 0; i < this.所处之宫.GetLength(0); i++)
                    {
                        this.labelDown.Text += " " + ((int)this.所处之宫[i]).ToString() + this.所处之宫[i].ToString() + this.地盘奇仪[i].ToString();
                    }

                }//if
            }
        }

        private bool isZF;
        public bool 是否值符
        {
            get { return isZF; }
        }

        private String theGod;
        public String 八神
        {
            get { return theGod; }
        }

        private e八门 theDoor;
        public e八门 八门
        {
            get { return theDoor; }
        }
        
        private e九星[] theStar;
        public e九星[] 九星
        {
            get { return theStar; }
        }

        private e三奇六仪[] theUpperQiYi;
        public e三奇六仪[] 天盘奇仪
        {
            get { return theUpperQiYi; }
        }

        private e三奇六仪[] theDownQiYi;
        public e三奇六仪[] 地盘奇仪
        {
            get { return theDownQiYi; }
        }

        private e九宫数[] thePalace;
        public e九宫数[] 所处之宫
        {
            get { return thePalace; }
        }

        public int 局数;
        public e八门 值使;
        public e九星 值符;
        public ZYDateTime 当时八字;

        private void QMCellCtrl_Click(object sender, EventArgs e)
        {
            FormDetails FormDetail = new FormDetails();

            FormDetail.是否值符 = this.是否值符;
            FormDetail.八神 = this.八神;
            FormDetail.八门 = this.八门;
            FormDetail.九星 = this.九星;
            FormDetail.天盘奇仪 = this.天盘奇仪;
            FormDetail.地盘奇仪 = this.地盘奇仪;
            FormDetail.所处之宫 = this.所处之宫;
            FormDetail.局数 = this.局数;
            FormDetail.值使 = this.值使;
            FormDetail.值符 = this.值符;
            FormDetail.当时八字 = this.当时八字;

            FormDetail.ShowDialog();
        }
    }
}
